package Pronostics;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;



/**
 * Classe permettant l'affichage de la fenetre pour l'ajout d'un joueur.
 * @author Nicolas Rault
 *
 */
public class AddPlayerWindow extends JFrame implements ActionListener{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static AddPlayerWindow singletonAddPlayerWindow;
	private JTextField name;
	//private Pronostics prono;
	
	private AddPlayerWindow(){
		super("Ajouter un joueur");
		//this.setTitle("Enregistrement");
		this.setSize(280,100);
		this.setLocationRelativeTo(this.getParent());
		
		name = new JTextField();
		name.addActionListener(this);
		add(name,BorderLayout.CENTER);
		
		JButton valid = new JButton("Valider");
		valid.addActionListener(this);
		add(valid, BorderLayout.SOUTH);

	}
	
	public static AddPlayerWindow getInstance() {
		if (singletonAddPlayerWindow == null) {
			singletonAddPlayerWindow = new AddPlayerWindow();
		}
		return singletonAddPlayerWindow;
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		String nomBouton = e.getActionCommand();
		if(nomBouton.equals("Valider")){
			String newPlay = "Test";
			newPlay = name.getText();
			Pronostics prono = Pronostics.getInstance();
			prono.addComboBox(newPlay);
			this.setVisible(false);
			name.setText("");
		}else{
			this.setVisible(false);
			name.setText("");
		}
		
	}
	
}
